package com.ruoyi.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.service.ITBalanceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TAccount;
import com.ruoyi.system.service.ITAccountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资金账户Controller
 * 
 * @author ruoyi
 * @date 2022-03-17
 */
@RestController
@RequestMapping("/system/account")
public class TAccountController extends BaseController
{
    @Autowired
    private ITAccountService tAccountService;

    @Resource
    private ITBalanceService itBalanceService;

    /**
     * 查询资金账户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TAccount tAccount)
    {
        startPage();
        List<TAccount> list = tAccountService.selectTAccountList(tAccount);
        return getDataTable(list);
    }

    /**
     * 导出资金账户列表
     */
    @Log(title = "资金账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAccount tAccount)
    {
        List<TAccount> list = tAccountService.selectTAccountList(tAccount);
        ExcelUtil<TAccount> util = new ExcelUtil<TAccount>(TAccount.class);
        util.exportExcel(response, list, "资金账户数据");
    }

    /**
     * 获取资金账户详细信息
     */
    @GetMapping(value = "/{aid}")
    public AjaxResult getInfo(@PathVariable("aid") Long aid)
    {
        return AjaxResult.success(tAccountService.selectTAccountByAid(aid));
    }

    /**
     * 新增资金账户
     */
    @Log(title = "资金账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAccount tAccount)
    {
        return toAjax(tAccountService.insertTAccount(tAccount));
    }

    /**
     * 修改资金账户
     */
    @Log(title = "资金账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAccount tAccount)
    {
        return toAjax(tAccountService.updateTAccount(tAccount));
    }

    /**
     * 删除资金账户
     */
    @Log(title = "资金账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{aids}")
    public AjaxResult remove(@PathVariable Long[] aids)
    {
        return toAjax(tAccountService.deleteTAccountByAids(aids));
    }
}
